<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>库存清单</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <style>
      .padding_r_15{
        padding-right: 15px !important;
      }
    </style>
</head>

<body>
	<div class="mui-content">
		<ul class="mui-table-view01">
			 <li class="search-cell">
			 	<div class="mui-input-row mui-search">
					<input type="search" id="searchText" onclick="openSearchWin()" readonly="readonly" class="mui-input-clear" placeholder="请输入关键字搜索" ><span class="mui-icon mui-icon-clear mui-hidden"></span><span class="mui-placeholder"><span></span></span>
				</div>
				<div class="mui-btn mui-btn-primary" onclick="Search()">
					搜索
				</div>
			 </li>
		</ul>
		<div class="mui-content" id="ordrListsContent">
			<script type="text/template" id="itemslist">
			{{each datas as item i}}
			<div class="mui-card">
				<ul class="mui-table-view mui-table-view-chevron">
					<li class="mui-table-view-cell mui-collapse">
						<a class="mui-navigate-right" href="#">{{item.itemnum}} {{item.description}}
							<span class="mui-badge mui-badge-inverted">余量:{{item.curbal}}</span>
						</a>
						<ul class="mui-table-view mui-table-view-chevron padding_r_15">
							<li class="mui-table-view-cell">部件制造号：{{item.cMPNum}}</li>
							<li class="mui-table-view-cell">库存地址：{{item.binnum}}</li>
							<li class="mui-table-view-cell">当前库存数：{{item.curbal}}</li>
							<li class="mui-table-view-cell">应用部位：{{item.cIssuelocation}}</li>
						</ul>
					</li>
				</ul>
				<div class="mui-card-footer">
					<a class="mui-card-link" tapmode onclick="openOrderDetailWin('{{item.inventoryid}}')">查看详情</a>
					<a class="mui-card-link"></a>
					<a class="mui-card-link" onclick="openOrderEditWin('{{item.itemid}}','{{item.inventoryid}}')">编辑</a>
				</div>
			</div>
			{{/each}}
            </script>
		</div>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/template.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	var FNScanner = null, UISearchBar = null;
	var cRegion = '', orderType = '', userID = '',statusId,searchText;
	apiready = function () {
		UISearchBar = api.require('UISearchBar');
		FNScanner = api.require('FNScanner');		
		cRegion = api.pageParam.location2;
		onLoadData(curPage,false);
		//alert("cRegion in apiready : " + cRegion);
		orderType = api.pageParam.orderType;
		scrollToBottomHandler(function() {
			if (!loadEnd) { // 没有结束时继续加载
				curPage++;
				onLoadData(curPage,true);
			} else { // 告诉到底了
				EndToast('到底了');
			}
		})
    api.addEventListener({
        name: 'upDataPage'
    }, function(ret, err) {
      if(ret.value.isrefersh == 'yes'){
        onLoadData(1,false)
      }
    });
		Refresh(function() {
			loadEnd = false;
			curPage = 1;
			onLoadData(curPage,false);
		});
		api.parseTapmode();
	    api.addEventListener({
	        name: 'renovate'
	    }, function(ret, err) {
	      if(ret.value.isRenovate == 'true'){
	        onLoadData(curPage,false);
	      }
	    })
	    api.addEventListener({
		    name:'navitembtn'
		},function(ret, err){
		    if(ret.type == 'right'){
		    	Scanner(4);
		    }
	  })
	}
	function openOrderDetailWin(inventoryid){
		openWin('stock_detail','物料详情',{
	        background: '#6098de',
	        color: '#fff',
	        rightButtons:[{
	        	iconPath:"widget://image/operate-icon.png"
	        }]
	    },{
	    	inventoryid:inventoryid
	    })
	}
  function openOrderEditWin(itemid,inventoryid){
		openWin('stock_edit','修改物料',{
	        background: '#6098de',
	        color: '#fff',
	        rightButtons:[{
	        	iconPath:"widget://image/save-icon.png"
	        }]
	    },{
	    	itemid:itemid,
	    	inventoryid:inventoryid
	    })
	}
	function onLoadData (page,load) {
		searchText = $api.val($api.byId('searchText'));
		ajaxrd("queryItemList", {
			location: cRegion,
			orderType: orderType,
      		isTodo:api.pageParam.isTodo ? api.pageParam.isTodo : 0,
			itemnum: searchText,
			pageNo: curPage,
			pageSize: 10
		}, function(ret, err) {
	      api.refreshHeaderLoadDone();
	      AddData('itemslist','ordrListsContent',ret.list,load);
	      if (ret.list.length < 10) {
	        loadEnd = true
	      }
		})
	}
	function openSearchWin(){
		UISearchBar.open({
		    placeholder: '请输入搜索关键字',
		    historyCount: 10,
		    showRecordBtn: false,
		    dataBase: 'stockList',
		    texts: {
		        cancelText: '取消',
		        clearText: '清除搜索记录'
		    },
		    styles: {
		        navBar: {
		            bgColor: '#3398dc',
		            borderColor: '#ccc'
		        },
		        searchBox: {
		            bgImg: '',
		            color: '#000',
		            height: 35,
		            size: 13
		        },
		        cancel: {
		            bg: 'rgba(0,0,0,0)',
		            color: '#fff',
		            size: 15
		        },
		        list: {
		            color: '#696969',
		            bgColor: '#FFFFFF',
		            borderColor: '#eee',
		            size: 15
		        },
		        clear: {
		            color: '#000000',
		            borderColor: '#ccc',
		            size: 15
		        }
		    }
		}, function(ret, err) {
		    if (ret && (ret.eventType == 'search' || ret.eventType == 'history')) {
		        $api.val($api.byId('searchText'),ret.text);
		        Search();
		    } else {
		        //alert(JSON.stringify(err));
		    }
		});
	}
</script>

</html>
